package com.fx.eduservice.controller.frot;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fx.commonuntils.ReturnMessage;
import com.fx.commonuntils.ReturnMessageUtils;
import com.fx.eduservice.entity.vo.EduCourse;
import com.fx.eduservice.entity.vo.EduTeacher;
import com.fx.eduservice.service.EduCourseService;
import com.fx.eduservice.service.EduTeacherService;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(description = "前端首页展示系统")
@RestController
@RequestMapping("/eduservice/indexfront")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
@CrossOrigin//解决跨域问题

public class IndexFrontController {
    final private EduCourseService eduCourseService;
    final private EduTeacherService eduTeacherService;



    @GetMapping("/index")
    public ReturnMessage<Object> index() {

        List<Object> list = Lists.newArrayList();


        //查询前8条热门课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> eduList = eduCourseService.list(wrapper);

        //查询前4条名师
        QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(wrapperTeacher);

        list.add(eduList);
        list.add(teacherList);

        return ReturnMessageUtils.success(list);
    }









}
